﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace TKT.Lifter.CIM.Lifter.TibcoMsg.Lifter
{
    public class TransferListReply : MessageBody
    {
        public string CommandID { get; set; }
        public string CarrierID { get; set; }
        public List<string> BoxIDList { get; set; }
        public string Source { get; set; }
        public string Destination { get; set; }
        public string Priority { get; set; }
        public string FGCode { get; set; }

        public TransferListReply()
            : base("TransferListReply")
        { }

        public override System.Xml.Linq.XElement ToXElement()
        {
            XElement body = new XElement("Body");
            body.Add(new XElement("COMMANDID", this.CommandID));
            body.Add(new XElement("CARRIERID", this.CarrierID));

            XElement idlist = new XElement("BOXIDLIST");
            if (this.BoxIDList != null)
            {
                foreach (var strBoxID in this.BoxIDList)
                {
                    idlist.Add(new XElement("BOXID", strBoxID));
                }
            }
            body.Add(idlist);

            body.Add(new XElement("SOURCE", this.Source));
            body.Add(new XElement("DESTINATION", this.Destination));
            body.Add(new XElement("PRIORITY", this.Priority));
            body.Add(new XElement("FGCODE", this.FGCode));

            return body;
        }

        public override void Parse(System.Xml.Linq.XElement body)
        {
            this.CommandID = body.Element("COMMANDID").Value;
            this.CarrierID = body.Element("CARRIERID").Value;
            List<XElement> boxidlist = body.Element("BOXIDLIST").Elements("BOXID").ToList();
            this.BoxIDList = new List<string>();
            foreach (var xelement in boxidlist)
            {
                string strBoxID = xelement.Value;
                this.BoxIDList.Add(strBoxID);
            }
            this.Source = body.Element("SOURCE").Value;
            this.Destination = body.Element("DESTINATION").Value;
            this.Priority = body.Element("PRIORITY").Value;
            this.FGCode = body.Element("FGCODE").Value;
        }
    }
}
